import hashlib
import time

from modules.base import BaseModule
from modules.executors import thread_pool_executor as tp
from modules.executors import process_pool_executor as pp


class Hasher(BaseModule):
    def process(self, task):
        return hashlib.md5(task).hexdigest()

    def process_single_thread(self, tasks):
        md5_list = []
        for task in tasks:
            md5_list.append(self.process(task))
        return md5_list

    def process_multi_thread(self, tasks):
        md5_list = []
        task_list = []
        for task in tasks:
            tp_task = tp.submit(self.process, task)
            task_list.append(tp_task)
        for task in task_list:
            md5 = task.result()
            md5_list.append(md5)
        return md5_list

    def process_multi_process(self, tasks):
        md5_list = []
        task_list = []
        for task in tasks:
            pp_task = pp.submit(self.process, task)
            task_list.append(pp_task)
        for task in task_list:
            md5 = task.result()
            md5_list.append(md5)
        return md5_list

    def process_coroutine(self, tasks):
        pass
